//
//  SearchListController.m
//  BaiTuan
//
//  Created by 看着太阳吃烧饼 on 16/1/4.
//  Copyright © 2016年 YR. All rights reserved.
//

#import "SearchListController.h"
#import "NearbyTableView.h"
#import "MenuView.h"

@interface SearchListController ()
@property (nonatomic, strong)MenuView *menu;
@property (nonatomic, strong)UISearchBar *search;

@end

@implementation SearchListController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createView];
}

-(void)viewDidAppear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    _search.hidden = NO;
}

- (void)createView
{
    UIButton *backButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 25, 25)];
    [backButton addTarget:self action:@selector(popAction:) forControlEvents:UIControlEventTouchUpInside];
    [backButton setImage:[UIImage imageNamed:@"btn_backItem.png"] forState:UIControlStateNormal];
    [backButton setImage:[UIImage imageNamed:@"btn_backItem_highlighted.png"] forState:UIControlStateHighlighted];
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc]initWithCustomView:(UIView *)backButton];
    self.navigationItem.leftBarButtonItem = barButton;
    
    _search = [[UISearchBar alloc]initWithFrame:CGRectMake(60, -10, kScreenWidth - 120, 64)];
    [self.navigationController.navigationBar addSubview:_search];
    _search.layer.cornerRadius = 10;
    _search.searchBarStyle = UISearchBarStyleMinimal;
    _search.delegate = self;
    _search.keyboardType = UIKeyboardTypeDefault;
    _search.placeholder = @"请输入商家名、品类或商圈...";

    
    //创建menu
    if (_menu == nil) {
        
        _menu = [[MenuView alloc]initWithOrigin:CGPointMake(0, 0) andHeight:45];
        [self.view addSubview:_menu];
    }
        
    //创建tableView
    _tableView = [[NearbyTableView alloc]initWithFrame:CGRectMake(0, 44, kScreenWidth, kScreenHeight - 64 - 45) style:UITableViewStylePlain];
    
    //导航栏不透明
    self.navigationController.navigationBar.translucent = NO;
    _tableView.rowHeight = 80;
    [self.view addSubview:_tableView];
    _tableView.dataArray = _dataArray;
}

//-(void)setDataArray:(NSArray *)dataArray
//{
//    if (_dataArray != dataArray) {
//        _dataArray = dataArray;
//        _tableView.dataArray = _dataArray;
//        [_tableView reloadData];
//    }
//}

#pragma mark - action

- (void)popAction:(UIButton *)button
{
    _search.hidden = YES;
    [self.navigationController popViewControllerAnimated:YES];
    [_search resignFirstResponder];
    
}

#pragma mark - UISearchBar delegate
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    [self popAction:nil];
    return YES;
}



@end
